package CycleTask;

import java.util.*;

/**
 * All rights Reserved, Designed By www.tusdao.com
 *
 * @version V1.0
 * @Title: TimeTest2.java
 * @Package CycleTask
 * @Description: TODO(用一句话描述该文件做什么)
 * @author: tusxxw
 * @date: 2020/9/2 3:07 下午
 * @Copyright: 2020 www.tbs.com Inc. All rights reserved.
 * <p>
 * 注意：本内容仅限于TBS项目组内部传阅，禁止外泄以及用于其他的商业目的
 */

public class TimeTest2 {


    public static Map<String,Boolean> runStatus = new HashMap<String, Boolean>();

    public void  run(String name, long t){
        final String key =  name;
        Timer timer = new Timer();
        Boolean status = runStatus.get(name);
        if(status == null) {
            runStatus.put(name, true);
            TimerTask timerTask = new TimerTask() {
                @Override
                public void run() {
                    if(runStatus.get(key)) {
                        System.out.println("任务执行中...");
                    } else {
                        System.out.println("任务停止....");
                        this.cancel();
                    }
                }
            };
            timer.schedule(timerTask,0, t);
        } else if (status) {
            runStatus.put(key, false);
            try{
                Thread.sleep(5000);
            }catch (Exception e) {
                e.printStackTrace();
            }
            runStatus.put(name, true);
            TimerTask timerTask = new TimerTask() {
                @Override
                public void run() {
                    if(runStatus.get(key)) {
                        System.out.println("222...");
                    } else {
                        System.out.println("任务停止....");
                        this.cancel();
                    }
                }
            };
            timer.schedule(timerTask,0, t);
        }
    }

    public static void main(String[] args) {
        TimeTest2 test2 = new TimeTest2();
        for (int i=0;i<10;i++) {
            Scanner scanner = new Scanner(System.in);
            long n = scanner.nextLong();
            System.out.println(n);
            test2.run("xxw",n);
        }
    }

}
